<template>
  <div>
    <div>
      <h4 class="font-weight-bold">打分卡执行明细</h4>
      <h6 class="font-weight-bold">
          企业客户：{{customerName}}&nbsp;&nbsp;&nbsp;&nbsp;
          打分卡：{{riskToolName}}&nbsp;&nbsp;&nbsp;&nbsp;
          最终得分：{{finalScore}}&nbsp;&nbsp;&nbsp;&nbsp;
          得分区间：
      </h6>
    </div>

    <sky-table 
    :data="table.data" 
    :columns="table.columns" 
    :show-index="table.showIndex" 
    class="mt-0"></sky-table>
  </div>
</template>

<script>
import Vue from "vue";

function padLeftZero (str) {
    return ('00' + str).substr(str.length);
};

function formatDate (longStr, fmt) {
   let date = new Date(longStr);

    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    }
    return fmt;
};

export default {
    name: "scoreCardRunResultDetail",
    metaInfo: {
        title: "打分卡指标节点执行明细"
    },
    components: {
    },
    data() {
        return {
            riskToolName:"",
            customerName:"",
            finalScore:"",
        table: {
          data: [],
          columns: [
            {
                title: "打分卡指标",
                key: "relationName"
            },
            {
              title: "判定节点",
              key: "sketchpadNodeName",
              align: "center"
            },      
            {
              title: "判定结果",
              key: "actionMark",
              render: (h, params) => {
                  let actionMarkName = "";
                    if(params.row.actionMark == 'true'){
                        actionMarkName = "通过";
                    }else if(params.row.actionMark == 'false') {
                        actionMarkName = "不通过";
                    }else {
                        actionMarkName = params.row.actionMark;
                    }
                    let actionTypeName = "";
                    if(params.row.actionType == 'NoAction'){
                        actionTypeName = '（无动作）';
                    } else if(params.row.actionType == 'Action'){
                        actionTypeName = '（调整分数）';
                    } else if(params.row.actionType == 'LinkNode'){
                        actionTypeName = '（子判定）';
                    }
                    return (
                        <div>
                            {actionMarkName}{actionTypeName}
                        </div>
                    );
                }
            },
            {
              title: "判定时间",
              width:150,
              key: "createDate",
              render: (h, params) => {
                  let createDate = null;
                  if(params.row.oid != null){
                    createDate = formatDate(params.row.createDate,'yyyy-MM-dd hh:mm:ss');
                  }
                    return (
                        <div>
                            {createDate}
                        </div>
                    );
                }
            }
          ]
        },
        defaultModalSize: null,
        relationName:""
    }},
    filters: {
        formatDate(time) {
        var date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd');
      }
    },
    created() {
        let self = this;
    },
    mounted() {
        this.oid = this.$route.query.oid;
        this.riskToolName = this.$route.query.riskToolName;
        this.customerName = this.$route.query.customerName;
        this.finalScore = this.$route.query.finalScore;
        this.loadToolNodeRunLogData();
    },
    methods: {
        loadToolNodeRunLogData() {
            let self = this;

            let url =
                "/app/v1/toolRunLogs/" +
                this.oid + 
                "/toolNodeRunLogs?pageSize=1000&riskToolType=scoreCard";

            self.$http.get(url).then(res => {
                // console.log(res);         
                self.table.data = res.data.data ? res.data.data : [];
            });
        }
    }
};
</script>
